package com.qfhd.soft.cjzcore.UI.MulitRecycle.viewholder;

import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qfhd.soft.cjzcore.Core.CJLogger;
import com.qfhd.soft.cjzcore.Core.CJTime;
import com.qfhd.soft.cjzcore.UI.MulitRecycle.bean.Task_try_Bean;
import com.qfhd.soft.cjzcore.R;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;

public class Task_try_ViewHolder extends BaseViewHolder {
//    @BindView(R.id.task_try_icon)
    private QMUIRadiusImageView icon;
//    @BindView(R.id.task_try_title)
    private TextView tx_title;
//    @BindView(R.id.task_try_subTitle)
    private TextView tx_subTitle;
//    @BindView(R.id.task_try_coin)
    private TextView tx_coin;
//    @BindView(R.id.task_try_getBtn)
    private TextView tx_getBtn;

    public Task_try_ViewHolder(View itemView) {
        super(itemView);
//        ButterKnife.bind(this, itemView);
        icon = (QMUIRadiusImageView) itemView.findViewById(R.id.task_try_icon);
        tx_title = (TextView) itemView.findViewById(R.id.task_try_title);
        tx_subTitle = (TextView) itemView.findViewById(R.id.task_try_subTitle);
        tx_coin = (TextView) itemView.findViewById(R.id.task_try_coin);
        tx_getBtn = (TextView) itemView.findViewById(R.id.task_try_getBtn);
    }
    @Override
    public void bindViewData(Object data) {
        Task_try_Bean bean = (Task_try_Bean)data;
        Glide.with(bean.getmContext())
                .load(bean.getData().icon)
                .centerCrop()
                .placeholder(bean.getmContext().getResources().getDrawable(R.drawable.placeholder))
                .into(icon);
        tx_title.setText(bean.getData().title);
        tx_coin.setText("+" + bean.getData().coin + "金币");

        if(bean.getData().isGetTask()){
            tx_getBtn.setBackground(bean.getmContext().getResources().getDrawable(R.drawable.radius_10_gray));
            tx_getBtn.setEnabled(false);
            tx_getBtn.setText("进行中");
//            CJLogger.v("3_timeStamp:" + bean.getData().timeStamp);
//            CJLogger.v("3_timeStamp:" + CJTime.getTimeStringFromTimeStamp(bean.getData().timeStamp));
            //判断 任务是第几阶段(用时间判断 不是当天就不用出现截止时间)
            String date_try = CJTime.getTimeFormatYYMMDD(bean.getData().timeStamp*1000);
            String date_now = CJTime.getTimeFormatYYMMDD(CJTime.getCurrentTimeMillis());
            CJLogger.v("");
            CJLogger.v("Task_try_ViewHolder date_try:" + date_try + " date_now:" + date_now);
            if(date_now.equalsIgnoreCase(date_try)){
                tx_subTitle.setText("截止时间：" + CJTime.getTimeStringFromTimeStamp(bean.getData().timeStamp + bean.getData().validTime));
            }
            else{
                tx_subTitle.setText("进行中...");
            }

        }
        else{
            tx_getBtn.setBackground(bean.getmContext().getResources().getDrawable(R.drawable.radius_10_theme));
            tx_getBtn.setEnabled(true);
            tx_getBtn.setText("获取");
            tx_getBtn.setOnClickListener(v -> {
                if(bean.getListener() != null){
                    bean.getListener().finish(bean);
                }
            });
            tx_subTitle.setText("剩余：" + bean.getData().remain + "个");
        }
    }

    public void String(){

    }
}
